class DateUtil

  Dateformat="%m/%d/%Y"  #format: '07/05/2006'
  #Dateformat="%b %d, %Y" #format: 'Jul 05, 2006'
  
  Timeformat="%m/%d/%Y %H:%M:%S"  #format: '07/05/2006 12:24:14'
  
  def self.showdate(indate)
    return "" if indate == nil
    begin
        return indate.strftime(Dateformat)
    rescue
        return indate
    end
  end
  
  def self.dateformat(indate,format)
    begin
        return indate.strftime(format)
    rescue
        return indate
    end
  end
  
  def self.showtime(intime)
    begin
        return intime.strftime(Timeformat)
    rescue
        return intime
    end
  end
  
  def self.timeformat(intime,format)
    begin
        return intime.strftime(format)
    rescue
        return intime
    end
  end
  
  def self.user2utc(current_user,time)
    (current_user == nil or current_user.time_zone == nil) ? time : current_user.tz.unadjust(time)
  end
  
  def self.utc2user(current_user,time)
    (current_user == nil or current_user.time_zone == nil) ? time : current_user.tz.adjust(time) 
  end
  
  def self.getDateListbyMonth(year,month)
    resultArr = Array.new
    begin
      require 'date'
      resultArr = Array.new
      beginDate = Date.new(year.to_i,month.to_i,1)  
      endDate = (beginDate >> 1) - 1
      (beginDate .. endDate) .each do |curDate|
        resultArr << curDate
      end
    rescue
    end
    return resultArr
  end
end